from rest_framework import serializers

from cart import models

from course.models import CourseModel


class CartSerializer(serializers.ModelSerializer):
    courselist = serializers.SerializerMethodField()

    def get_courselist(self, obj):
        coursedata = CourseModel.objects.filter(id=obj.course.id).first()
        return {"name": coursedata.name, "image": coursedata.image, "price": coursedata.price, "courseid": coursedata.id}

    class Meta:
        model = models.CartModel
        fields = '__all__'
